/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Factory;



import Server.*;
import Client.*;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author manelv8
 */
public  class SocketFactory {
    public static final int TCP =1;
    public static final int UDP = 2;
    public static InterfaceServerSocket getServer(int tipo, int porta) throws IOException{
        if(tipo == TCP){
            return new ServerSocketTCP(porta);
        }else if(tipo == UDP){
            return new ServerSocketUDP(porta);
        }else
            return null;
        
    }
    
    public static  InterfaceClientSocket getClient(int tipo,int porta, String host){
        if(tipo == TCP){
            try {
                return new ClientSocketTCP(host,porta);
            } catch (UnknownHostException ex) {
                Logger.getLogger(SocketFactory.class.getName()).log(Level.SEVERE, null, ex);
                return null;
            } catch (IOException ex) {
                Logger.getLogger(SocketFactory.class.getName()).log(Level.SEVERE, null, ex);
                return null;
            }
        }else if(tipo == UDP){
            return new ClientSocketUDP(host,porta);
        }else
            return null;
        
    }
    
    
    
    
    
}
